#include"tim5.h"

void tim5_init(void)
{
    RCC->APB2ENR|=RCC_APB2ENR_IOPAEN;
    RCC->APB1ENR|=RCC_APB1ENR_TIM5EN;

    //PA0 mode11  cnf10
    GPIOA->CRL|=GPIO_CRL_MODE0;
    GPIOA->CRL|=GPIO_CRL_CNF0_1;
    GPIOA->CRL&=~GPIO_CRL_CNF0_0;

    //配置pcs
    TIM5->PSC=719;
    TIM5->ARR=99;

    TIM5->CR1&=~TIM_CR1_DIR;

    TIM5->CCMR1&=~TIM_CCMR1_CC1S;
    TIM5->CCMR1|=TIM_CCMR1_OC1M_2;
    TIM5->CCMR1|=TIM_CCMR1_OC1M_1;
    TIM5->CCMR1&=~TIM_CCMR1_OC1M_0;
    //TIM5->CCMR1|=TIM_CCMR1_OC1CE;
    //TIM5->CCMR1&=~TIM_CCMR1_OC1FE;

    TIM5->CCER|=TIM_CCER_CC1E;
    TIM5->CCER&=~TIM_CCER_CC1P;
    TIM5->CCR1=50;
}

void tim5_start(void)
{
    TIM5->CR1|=TIM_CR1_CEN;
}

void tim5_stop(void)
{
    TIM5->CR1&=~TIM_CR1_CEN;
}
void tim5_pwm(uint8_t duty)
{
    TIM5->CCR1=duty;
}